<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use App\Service\FangService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Swagger\Annotation as SA;
use Hyperf\Swagger\Request\SwaggerRequest;

#[SA\HyperfServer('http')]
class IndexController extends Controller
{
    #[Inject]
    protected FangService $fangService;

    public function index()
    {
        return $this->response->success([
            'user' => 'Hyperf',
            'message' => 'Hello World',
        ]);
    }

    #[SA\Get(path: '/list_zufang', summary: '租房列表', tags: ['房产接口'])]
    #[SA\Response(response: '200', content: new SA\JsonContent(ref: null))]
    public function listZufang()
    {
        $list = $this->fangService->listZufang();
        return $this->response->success($list);
    }

    #[SA\Get(path: '/list_shoufang', summary: '售房列表', tags: ['房产接口'])]
    #[SA\Response(response: '200', content: new SA\JsonContent(ref: null))]
    public function listShoufang()
    {
        $list = $this->fangService->listShoufang();
        return $this->response->success($list);
    }

    #[SA\Get(path: '/detail', summary: '房屋详情', tags: ['房产接口'])]
    #[SA\RequestBody(content: new SA\JsonContent(properties: [
        new SA\Property(property: 'id', description: 'ID', type: 'int', rules: 'required|int'),
        new SA\Property(property: 'kind', description: '类型', type: 'string', rules: 'required|string'),
    ]))]
    #[SA\Response(response: '200', content: new SA\JsonContent(ref: null))]
    public function detail(SwaggerRequest $request)
    {
        $get = $request->all();
        $id = $get['id'];
        $kind = $get['kind'];
        var_dump($id, $kind);
        $data = $this->fangService->getFangDetail($id, $kind);

        return $this->response->success($data);
    }
}
